Hello, |
Re: copying contents of a string to another string
Hi,
string line = " RANDOM STRING WITH SPACES"
int y
string new_s= ""
for (y = 0; y< length(line); y++) {
if (isspace(line[y]))
continue
print line[y]
new_s += ("" line[y] "")
}
line[y] ""
|
Re: copying contents of a string to another string adevicq - Mon Nov 12 04:05:36 EST 2012
Hi,
string line = " RANDOM STRING WITH SPACES"
int y
string new_s= ""
for (y = 0; y< length(line); y++) {
if (isspace(line[y]))
continue
print line[y]
new_s += ("" line[y] "")
}
line[y] ""
The result I want (.ei if I do print new_s at the end) is a string that contains now spaces, no newline chars, i.e. "RANDOMSTRINGWITHSPACES". After playing around with the strange looking space ' ' character that is used for concatenation, I got a result. string line = " RANDOM STRING WITH SPACES" int y string new_s= "" for (y = 0; y< length(line); y++) { if (isspace(line[y])) continue new_s = new_s liney:y } print new_s thanks for pointing me in the right direction! |
Re: copying contents of a string to another string MyDeveloerWorks - Mon Nov 12 04:59:09 EST 2012 new_s = new_s liney:y |
Re: copying contents of a string to another string Don't concatenate inside a loop, use a buffer instead:
Buffer bufStripSpaces = create() // Local to following function
string StripSpaces(string in_String)
{
int y
char c
bufStripSpaces = ""
for (y = 0; y< length(in_String); y++) {
c = in_String[y]
if (isspace(c) ) continue
bufStripSpaces += c
}
return(stringOf(bufStripSpaces))
} // end StripSpaces()
void DoTest(string in_String)
{
string Results = StripSpaces(in_String)
print in_String "\t[" Results "]\n"
}
DoTest(" RANDOM STRING WITH SPACES")
which is space, TAB, EOL, and MS-Word LF, page-break, and CR.
|